'''
Created on Jan 10, 2010

@author: Berin
'''

import pygame
class Tile(object):
    '''
    Represents a local Tile
    '''

    def __init__(self, (xPos, yPos), (width, height), surface = None, str = None):
        self.selected = False
        self.xPos = xPos
        self.yPos = yPos
        self.xSize = width
        self.ySize = height
        self.elevated_surface = []
        self.rect = surface.get_rect()
        if str != None:
            for x in str:
                temp_surf = pygame.image.fromstring(x,(self.xSize,self.ySize), "RGBA")
                temp_surf.set_colorkey((255,255,255))
                self.elevated_surface.append(temp_surf)
        elif surface != None:
            try:
                surface.set_colorkey((255,255,255))
            except:
                pass
            self.elevated_surface.append(surface)
            
        self.fail_Safe = 0
    
    def toString(self):
        temp_str = []
        for clips in self.elevated_surface:
            temp_str.append(pygame.image.tostring(clips, "RGBA"))
        return (self.xPos, self.yPos), (self.xSize, self.ySize), temp_str
    
    def get_Surface(self):
        return self.elevated_surface
    
    def get_rect(self):
        return pygame.Rect(self.xPos, self.yPos, self.xSize, self.ySize)
        
    def get_X(self):
        return self.xPos
        
    def get_Y(self):
        return self.yPos
        
    def add_elevation(self, surface):
        surface.set_colorkey((255,255,255))
        for clips in self.elevated_surface:
            if clips == surface:
                return
        self.elevated_surface.append(surface)
            
    def remove_elevation(self, failSafe):
        if failSafe == self.fail_Safe:
            return True
        self.fail_Safe = failSafe
        if len(self.elevated_surface) < 2:
            return False
        else:
            self.elevated_surface = self.elevated_surface[0:-1]
            
        return True
        
    def set_selected(self, selected):
        self.selected = selected
            
    def get_color(self):
        if self.selected == True:
            return (0,255,0)
        elif self.selected == False:
            return (140,140,140)
        